function rho = zFC_acf(x,k)

% Computes autocorrelation function for lag k
% checked on Stata

T = max(size(x));
xbar = mean(x);

denom = 0; numer = 0;

for t = 1:T-k
   numer = numer + (x(t)-xbar)*(x(t+k)-xbar);
end

for t = 1:T
   denom = denom + (x(t)-xbar)^2;  
end

rho = numer/denom;

end